
import urllib.request
import urllib.error

url = 'https://blog.csdn.net/qiushi_1990/article/details/139960609'

headers = {
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
}

try:
    request = urllib.request.Request(url=url,headers=headers)
    response = urllib.request.urlopen(request)
    content = response.read()
    content_decode = content.decode('utf-8')
    print(content_decode)
except urllib.error.HTTPError:
    print('URL地址有误')
except urllib.error.URLError:
    print('主机名错误')



# urllib.error.HTTPError: HTTP Error 404: Not Found



